package com.ucomm.talent.activity.detail;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.ViewStub;
import android.widget.TextView;

import com.ucomm.talent.AppConfig;
import com.ucomm.talent.AppConstants;
import com.ucomm.talent.AppException;
import com.ucomm.talent.R;
import com.ucomm.talent.activity.IHeaderBarClickListener;
import com.ucomm.talent.common.DebugUtil;
import com.ucomm.talent.manager.DetailSearchManager;
import com.ucomm.talent.model.HotCompanyDetailsInfo;
import com.ucomm.talent.model.HotCompanyInfo;
import com.ucomm.talent.widget.CustomProgressDialog;
import com.ucomm.talent.widget.MainHeaderBar;
/**
 * 
 * @author Administrator
 * @Description: 热门企业详细信息显示界面
 * @date:2013-6-22
 *
 */
public class HotComDetailActivity extends Activity implements IHeaderBarClickListener{
	
	private CustomProgressDialog customProgressDialog;
	private MainHeaderBar mainHeaderBar;
	private DetailSearchManager detailSearchManager;
	private ViewStub companyDetailsViewStub;
	private int id = 0;
	private TextView comName;
	private TextView properties_tv;
	private TextView est_date_tv;
	private TextView firm_size_tv;
	private TextView register_cap_tv;
	private TextView address_tv;
	private TextView job_style_tv;
	private TextView com_info_tv;
	
	Handler mHandler = new Handler(){
        @Override
    public void handleMessage(Message msg) {
        int what = msg.what;
        DebugUtil.Log(HotComDetailActivity.this,"---------- " + customProgressDialog.toString());
        switch (what){
            case AppConstants.MsgStatus.MSG_ERROR:
                if (customProgressDialog != null && customProgressDialog.isShowing())
                    customProgressDialog.dismiss();
                ((AppException)msg.obj).makeToast(HotComDetailActivity.this);
                break;
            case AppConstants.MsgStatus.MSG_SUCCUSS:
                if (customProgressDialog != null && customProgressDialog.isShowing())
                    customProgressDialog.dismiss();
                //获取数据
                HotCompanyDetailsInfo details = (HotCompanyDetailsInfo) msg.obj;
                String properties = null;//企业性质
                String est_date = null;//成立时间
                String firm_size = null;//公司规模
                String address = null;//地址
                String job_style = null;//所属行业
                if(AppConfig.comMap.size()!=0 && AppConfig.industryMap.size()!=0 && AppConfig.cityMap.size() !=0){
                	properties = AppConfig.comMap.get(details.getCompanyPro());
                	firm_size = AppConfig.comMap.get(details.getMun());
                	address = AppConfig.cityMap.get(details.getProvinceId()) + AppConfig.cityMap.get(details.getCityId());
                	job_style = AppConfig.industryMap.get(details.getHy());
                }
                properties_tv.setText(properties);
                est_date_tv.setText(details.getsDate());
                firm_size_tv.setText(firm_size);
                register_cap_tv.setText(details.getMoney()+"万元");
                address_tv.setText(address);
                job_style_tv.setText(job_style);
                com_info_tv.setText(details.getDescription());
                
                break;
            case AppConstants.MsgStatus.MSG_LOADING:
                if (customProgressDialog != null && !customProgressDialog.isShowing())
                    customProgressDialog.show();
                break;
            default:
                break;
        }
        super.handleMessage(msg);
    }
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hot_com_detail_layout);
		//获取数据
		Intent i = getIntent();
		HotCompanyInfo info = (HotCompanyInfo) i.getSerializableExtra("info");
		//获取企业id根据企业id获取详细信息
		id = info.getCompanyId();
		comName = (TextView) findViewById(R.id.com_name);
		comName.setText(info.getCompanyName());
		initView();
        detailSearchManager = new DetailSearchManager(this, mHandler);
        final String url = AppConstants.HOT_COMPANY_DETAILS+id;
        detailSearchManager.searchDetailDataFromNetwork(url);
	}
	private void initView(){
		mainHeaderBar = (MainHeaderBar) findViewById(R.id.main_header_bar);
		mainHeaderBar.setBarClickListener(this);
		customProgressDialog = new CustomProgressDialog(this);
		companyDetailsViewStub = (ViewStub) findViewById(R.id.hot_com_details_vs2);
		companyDetailsViewStub.inflate();
		properties_tv = (TextView) findViewById(R.id.properties_tv);
		est_date_tv = (TextView) findViewById(R.id.est_date_tv);
		firm_size_tv = (TextView) findViewById(R.id.firm_size_tv);
		register_cap_tv = (TextView) findViewById(R.id.register_cap_tv);
		address_tv = (TextView) findViewById(R.id.address_tv);
		job_style_tv = (TextView) findViewById(R.id.job_style_tv);
		com_info_tv = (TextView) findViewById(R.id.com_info_tv);
		
	}

	@Override
	public void onBackButtOnClick(View view) {
		finish();
	}

	@Override
	public void onExitButtonOnClick(View view) {
		// TODO Auto-generated method stub
		
	}
}

